﻿//加载行程
function loadCaltrans()
{
    $.ui.showMask("正在加载...");
    if ($("#hiddatas").val() == null || $("#hiddatas").val() == "")
        $.post('ProcTeacher/GetCalendar.ashx', { YMType: "" }, function (data) { $("#hiddatas").val(data); loaddata(data); });
    else
        loaddata($("#hiddatas").val());
}
function loaddata(obj)
{
    var myDate = new Date();
    var mon = myDate.getMonth() + 1;
    if (mon < 10)
        mon = "0" + mon;
    var ym = myDate.getFullYear() + mon;
    loadCalendar(obj, ym);
    $.ui.loadContent('jqmxingchengbiao', false, false, 'flip');
}
function loadCalendar(ds, ym)
{
    var nums, first;
    first = ds.substr((ds.indexOf(ym) + 6), 1);
    $("#hdffirst").val(first);
    nums = ds.substr((ds.indexOf(ym) + 7), 2);
    var date = 1;
    var setdate = "";
    for (var i = (parseInt(first, 10) + 1), max = (parseInt(first, 10) + 1 + parseInt(nums, 10)); i < max; i++)
    {
        if (parseInt(date, 10) < 10)
            setdate = "0" + date;
        else
            setdate = date;
        $("#lid" + i).html(setdate);
        $("#lid" + i).bind("click", function (evt) { lionclick(this); });
        date++;
    }
    $("#labdate").text(ym);
    //加载当月行程
    $.post('ProcTeacher/GetData.ashx', { TYPE: "teacalendar", PARA: $("#hiduserid").val() + "︾" + ym }, function (data) { loadteachtrans(data, first); });

    $.ui.hideMask();
}
function unload()
{
    $("#hiduserid").val("");
    window.location.href = "login.htm?unload=1";
}
function loadteachtrans(data, first)
{
    if (data != "")
    {
        var ds = data.split(';');
        var ds1, ds2;
        for (var i = 0; i < ds.length; i++)
        {
            ds1 = parseInt(ds[i].substr(0, 2), 10);
            $("#lid" + (ds1 + parseInt(first))).html($("#lid" + (ds1 + parseInt(first))).text() + "<br>" + ds[i].substr(2));
        }
    }
}
//年月变换
function ChangeYM(obj)
{
    $.ui.showMask("正在加载...");
    var nowym = $("#labdate").text();
    if (nowym == null || nowym == "")
        return;
    var change = 1;
    var wy = parseInt(nowym.substr(0, 4), 10);
    var wm = parseInt(nowym.substr(4, 2), 10);
    switch (obj)
    {
        case "prey":
            if (wy > 2010)
                wy--;
            else
                change = 0;
            break;
        case "prem":
            if (wm == 1)
            {
                wy--;
                if (wy < 2010)
                { change = 0; }
                wm = 12;
            }
            else
            {
                wm--;
            }
            break;
        case "nextm":
            if (wm == 12)
            {
                wy++;
                if (wy > 2020)
                { change = 0; }
                wm = 1;
            }
            else
                wm++;
            break;
        case "nexty":
            if (wy < 2021)
                wy++;
            else
                change = 0;
            break;
    }
    //当时间小于2010或大于2020年时，不变更
    if (change == 1)
    {
        if (wm < 10)
            wm = "0" + wm;
        var ym = wy + "" + wm;
        for (var i = 1; i < 43; i++)
        {
            if ($("#lid" + i).hasClass("libackcolor"))
            {
                $("#lid" + i).removeClass("libackcolor");
            }
            $("#lid" + i).unbind("click");
            $("#lid" + i).html("");
        }
        loadCalendar($("#hiddatas").val(), ym);
    }
    else
    {
        $.ui.hideMask();
    }
}
//展示讲师行程
function loadteachcontent(data, de)
{
    $("#h2ymd").text(de);
    $("#divshangwu").html(""); //清空
    $("#divxiawu").html("");
    $("#divwanshang").html("");
    var object = $.parseJSON(data);
    for (var i = 0; i < object.length; i++)
    {
        var div;
        if (object[i].HmType == "上午")
        {
            div = $("#divshangwu");
        }
        else if (object[i].HmType == "下午")
        {
            div = $("#divxiawu");
        }
        else
        {
            div = $("#divwanshang");
        }
        div.html("公司名：" + object[i].CustomerName + "<br> 决策人：" + object[i].Decisionmaker + "(" + object[i].DecisionPosition + ")<br>时间：" + object[i].coursetime + "<br>地点：" + object[i].courseaddress);
    }
}

//列表日期选择
function lionclick(obj)
{
    for (var i = 1; i < 43; i++)
    {
        if ($("#lid" + i).hasClass("libackcolor"))
        {
            $("#lid" + i).removeClass("libackcolor");
        }
    }
    $("#" + obj.id).addClass("libackcolor");
    $("#hiddatesel").val($("#" + obj.id).text());


    var de = parseInt(obj.id.substr(3), 10) - parseInt($("#hdffirst").val(), 10);
    if (de < 10)
        de = "0" + de;
    $("#hdfymd").val($("#labdate").text() + de);
    $("#labchangtype").text(""); //清空
}

//设置总结界面 日期、场次
function SetLabValue(obj)
{
    if (obj == "上")
        $("#labchangtype").text($("#hdfymd").val() + "上午场");
    else if (obj == "下")
        $("#labchangtype").text($("#hdfymd").val() + "下午场");
    else
        $("#labchangtype").text($("#hdfymd").val() + "晚上场");
}
//总结跳转判断
function showChangci()
{
    $.ui.showMask("正在加载...");
    if ($("#labchangtype").text() != "")
    {
        $.ui.loadContent('trasummary', false, false, 'pop');
    }
    else
    {
        if ($("#hiddatesel").val() == "")
        {
            alert("请选择日期！");
            $.ui.hideMask();
            return;
        }
        var sxw = $("#hiddatesel").val().substr(2);
        if (sxw == "")
        {
            alert("该日期不存在行程，无法写总结！");
            $.ui.hideMask();
            return;
        }
        else if (sxw.length == 1)
        {
            SetLabValue(sxw);
            loadsums(); //直接进入
        }
        else
        {
            var mes1 = "<p><input type='radio' value='no' id='Changci1' onclick='SetLabValue(\"上\");' name='Changci' class='jq-ui-forms' /><label for='no'>上午场</label><br></p>";
            var mes2 = "<p><input type='radio' value='no' id='Changci2' onclick='SetLabValue(\"下\");' name='Changci' class='jq-ui-forms' /><label for='no'>下午场</label><br></p>";
            var mes3 = "<p><input type='radio' value='no' id='Changci3' onclick='SetLabValue(\"晚\");' name='Changci' class='jq-ui-forms' /><label for='no'>晚上场</label><br></p>";
            var mes = "";
            if (contains(sxw, "上", false))
                mes += mes1;
            if (contains(sxw, "下", false))
                mes += mes2;
            if (contains(sxw, "晚", false))
                mes += mes3;
            $("#jQUi").popup({ title: "请选择场次",
                message: mes,
                cancelText: "取消",
                cancelCallback: function () { $.ui.hideMask(); },
                doneText: "进入总结",
                doneCallback: function () { if ($("#labchangtype").text() == "") { alert("请选择场次！"); return; } else { loadsums(); } },
                cancelOnly: false
            });
        }
    }
}
//进入日总结界面
function loadsums()
{
    $.post('ProcTeacher/GetData.ashx', { TYPE: "loadsumdata", PARA: $("#labchangtype").text() + "︾" + $("#hiduserid").val() }, function (data) { loadSumData(data); });

}
//进入日行程界面
function loadtrans()
{
    if ($("#hdfymd").val() == "")
    {
        alert("请选择日期！");
    }
    else
    {
        $.ui.showMask("正在加载...");
        $.post('ProcTeacher/GetData.ashx', { TYPE: "calendarContent", PARA: $("#hiduserid").val() + "︾" + $("#hdfymd").val() }, function (data) { loadteachcontent(data, $("#hdfymd").val()); });
        $.ui.loadContent('DateTransContent', false, false, 'pop');
    }
}
//加载分公司信息
function loaddepartment(jsonstr)
{
    var select = document.getElementById("tsDepartment");
    if (select.options.length > 1)//值已存在，则返回
        return;
    else
    {
        for (i = 0, max = jsonstr.length; i < max; i++)
        {
            var newOption = document.createElement("OPTION");
            newOption.text = jsonstr[i].DeptName;
            newOption.value = jsonstr[i].DeptID;
            select.options.add(newOption);
        }
    }
}
//加载总结相关数据
function loadSumData(obj)
{
    if (obj != "")
    {
        var jsonstr = $.parseJSON(obj);
        loaddepartment(jsonstr.Dept);
        if (jsonstr.TeachSumup != null)
        {
            SetSumValue("TeachSumup", jsonstr.TeachSumup);
        }
        else
            SetSumValue("Customer", jsonstr);
        $.ui.loadContent('trasummary', false, false, 'pop');
    }
}
var cansave = true;
function CheckSave(val, title)
{
    if (!cansave)
        return;
    else if (val == null || val == "")
    {
        alert(title + "】必填或必选！");
        cansave = false;
    }
    else
    {
        return val;
    }
}
//总结保存
function funSave()
{
    cansave = true;
    var dtype = $("#labchangtype").text();
    var orderid = $("#tshdordercode").val();
    var sumarr = new TeachSumup("",
    orderid,
    $("#tshdthodometerid").val(),
    dtype.substr(0, 4) + "-" + dtype.substr(4, 2) + "-" + dtype.substr(6, 2),
    CheckSave(GetRadioValue("tssuccess"), "是否成交场"),
    CheckSave(GetRadioValue("tsstander"), "是否标准场"),
    CheckSave(GetRadioValue("tseffect"), "是否有效场"),
    CheckSave($("#tsDdlJWX").val(), "JWX指标"),
    "0",
    "",
    CheckSave(GetRadioValue("tscourse"), "是否上课场"), //11
    CheckSave($("#tsClassExplain").val(), "预计上大课时间"),
    "",
    CheckSave($("#tsCustomerPromis").val(), "对客户的承诺"),
    "00000000-0000-0000-0000-000000000000",
    $("#tsDepartment").val(),
    CheckSave($("#tsExplain").val(), "预计上大课地点"),
    $("#hiduserid").val(), //18
    new Date(),
    null,
    null,
    null,
    $("#tshdsumid").val(),
    null,
    null,
    dtype.substr(0, 4) + "-" + dtype.substr(4, 2) + "-" + dtype.substr(6, 2), //HmDate
    null,
    $("#labchangtype").text().substr(8, 2), //28
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    CheckSave($("#tsCompanyCreateDate").val(), "成立日期"), //43
    null,
    null,
    "",
    CheckSave($("#tsProductSum").val(), "产值"),
    null,
    null,
    null,
    null,
    null,
    $("#tsCharacter").val(),
    "",
    $("#tsbirthday").val(),
    $("#tsCredit").val(),
    $("#tsSchoolScientifc").val(),
    GetRadioValue("tsbirthdaytype"),
    $("#tsHomeplace").val(),
    $("#tsCustomerPhylogeny").val(),
    "",
    "1900-01-01",
    "",
    $("#tsBelowPersonsum").val(),
    $("#tsMiddlePersonsum").val(),
    $("#tsHighPersonsum").val(),
    "0",
    null,
    null,
    null,
    CheckSave($("#tsPersonSum").val(), "员工人数"), //71
    "",
    CheckSave($("#tsPainful").val(), "企业痛苦点"),
    CheckSave($("#tsPullulation").val(), "个人创业史"),
    null,
    null,
    CheckSave($("#tsBargainReason").val(), "成交原因及过程"),
    CheckSave($("#tsBargainDispute").val(), "成交中遇到的抗拒点"),
    "0"
    );
    if (cansave)
    {
        var type = "saveteasum" + $("#tshdtype").val();
        $.post('ProcTeacher/GetData.ashx', { TYPE: type, PARA: JSON.stringify(sumarr) },
        function (data)
        {
            if (data == "1")
                alert("保存成功！");
            else
                alert("操作失败！");

        });
    }
}
//展开隐藏
function showHide(obj, objToHide)
{
    var el = $("#" + objToHide)[0];

    if (obj.className == "expanded")
    {
        obj.className = "collapsed";
    }
    else
    {
        obj.className = "expanded";
    }
    $(el).toggle();

}
//日总结栏位展开隐藏
function h5showHide(obj, objToHide)
{
    var el = $("#" + objToHide)[0];

    if (obj.className == "h5expanded")
    {
        obj.className = "h5collapsed";
    }
    else
    {
        obj.className = "h5expanded";
    }
    $(el).toggle();
}
//通过值修改所选中的单选按钮
function setRadio(name, sRadioValue)
{
    var oRadio = document.getElementsByName(name);
    for (var i = 0; i < oRadio.length; i++) //循环
    {
        if (oRadio[i].value == sRadioValue) //比较值
        {
            oRadio[i].checked = true; //修改选中状态
            break; //停止循环
        }
    }
}
function GetRadioValue(RadioName)
{
    var obj;
    obj = document.getElementsByName(RadioName);
    if (obj != null)
    {
        var i;
        for (i = 0; i < obj.length; i++)
        {
            if (obj[i].checked)
            {
                return obj[i].value;
            }
        }
    }
    return null;
}
//日总结赋值
function SetSumValue(type, data)
{
    if (type == "TeachSumup")
    {
        $("#tshdsumid").val(data[0].ID);
        $("#tshdordercode").val(data[0].OrderId);
        $("#tsordercode").val(data[0].OrderCode);
        $("#tsCustomerCode").val(data[0].CustomerCode);
        $("#tsCustomerName").val(data[0].CustomerName);
        $("#tsUsername").val(data[0].UName);
        $("#tsSaleName").val(data[0].SaleadviserName);
        $("#tsTradename").val(data[0].TradeName);
        $("#tshdthodometerid").val(data[0].ThodometerId);
        $("#tsExplain").val(data[0].Explain);
        $("#tsClassExplain").val(data[0].ClassExplain);
        $("#tsDepartment").val(data[0].DeptId);
        $("#tsDdlJWX").val(data[0].JWXID);
        $("#tshdtype").val("1");
        $("#tsbirthday").val(data[0].DecisionBirthday);
        $("#tsHomeplace").val(data[0].Homeplace);
        $("#tsCharacter").val(data[0].Character);
        $("#tsSchoolScientifc").val(data[0].SchoolScientifc);
        $("#tsCredit").val(data[0].Credit);
        $("#tsPullulation").val(data[0].Pullulation);
        $("#tsCompanyCreateDate").val(data[0].CompanyCreateDate);
        $("#tsPersonSum").val(data[0].PersonSum);
        $("#tsHighPersonsum").val(data[0].HighPersonsum);
        $("#tsMiddlePersonsum").val(data[0].MiddlePersonsum);
        $("#tsBelowPersonsum").val(data[0].BelowPersonsum);
        $("#tsProductSum").val(data[0].ProductSum);
        $("#tsPainful").val(data[0].Painful);
        $("#tsCustomerPhylogeny").val(data[0].CustomerPhylogeny);
        $("#tsBargainReason").val(data[0].BargainReason);
        $("#tsBargainDispute").val(data[0].BargainDispute);
        $("#tsCustomerPromis").val(data[0].CustomerPromis);
        setRadio("tseffect", data[0].IsValue);
        setRadio("tsstander", data[0].IsStandard);
        setRadio("tssuccess", data[0].IsBargain);
        setRadio("tscourse", data[0].IsClass);
        setRadio("tsbirthdaytype", data[0].BirthdayType);
    }
    else
    {
        if (data.Order[0] != null)
        {
            $("#tshdordercode").val(data.Order[0].OrderId);
            $("#tsordercode").val(data.Order[0].OrderCode);
        }
        $("#tsCustomerCode").val(data.Customer[0].CustomerCode);
        $("#tsCustomerName").val(data.Customer[0].CustomerName);
        $("#tsUsername").val(data.Customer[0].UName);
        $("#tsSaleName").val(data.Customer[0].SaleadviserName);
        $("#tsTradename").val(data.Customer[0].TradeName);
        $("#tshdthodometerid").val(data.Thodometer[0].ThodometerId);
        $("#tsExplain").val(data.Customer[0].Explain);
        $("#tsClassExplain").val(data.Customer[0].ClassExplain);
        $("#tsDepartment").val(data.Customer[0].DeptId);
        $("#tsDdlJWX").val(data.Customer[0].JWXID);
        $("#tshdtype").val("0");
        $("#tsbirthday").val(data.Customer[0].DecisionBirthday);
        $("#tsHomeplace").val(data.Customer[0].Homeplace);
        $("#tsCharacter").val(data.Customer[0].Character);
        $("#tsSchoolScientifc").val(data.Customer[0].SchoolScientifc);
        $("#tsCredit").val(data.Customer[0].Credit);
        $("#tsPullulation").val(data.Customer[0].Pullulation);
        $("#tsCompanyCreateDate").val(data.Customer[0].CompanyCreateDate);
        $("#tsPersonSum").val(data.Customer[0].PersonSum);
        $("#tsHighPersonsum").val(data.Customer[0].HighPersonsum);
        $("#tsMiddlePersonsum").val(data.Customer[0].MiddlePersonsum);
        $("#tsBelowPersonsum").val(data.Customer[0].BelowPersonsum);
        $("#tsProductSum").val(data.Customer[0].ProductSum);
        $("#tsPainful").val(data.Customer[0].Painful);
        $("#tsCustomerPhylogeny").val(data.Customer[0].CustomerPhylogeny);
        $("#tsBargainReason").val(data.Customer[0].BargainReason);
        $("#tsBargainDispute").val(data.Customer[0].BargainDispute);
        $("#tsCustomerPromis").val(data.Customer[0].CustomerPromis);
        setRadio("tseffect", data.Customer[0].IsValue);
        setRadio("tsstander", data.Customer[0].IsStandard);
        setRadio("tssuccess", data.Customer[0].IsBargain);
        setRadio("tscourse", data.Customer[0].IsClass);
        setRadio("tsbirthdaytype", data.Customer[0].BirthdayType);
    }
}

function TeachSumup(Code, OrderId, ThodometerId, PrelectDate, IsBargain, IsStandard, IsValue, JWXID, IsGripe, GripeExplain, IsClass, ClassExplain, TeachPlace, CustomerPromis, TutorId, DeptId, Explain, Adduser, Addtime, EXP1, EXP2, EXP3, EXP4, DeptName, UName, HmDate, Expr2, HmType, OrderCode, CustomerCode, State, Province, City, Area, Address, CustomerName, MnemonicCode, IsHQ, Decisionmaker, DecisionPosition, DecisionTel, DecisionEmail, CompanyCreateDate, CompanyProduct, CompanyAttention, CompanyGain, ProductSum, CusTestimony, CusTrainbudget, ManagerQuestion, StrongPoint, Expr1, Character, DecisionFancy, DecisionBirthday, Credit, SchoolScientifc, BirthdayType, Homeplace, CustomerPhylogeny, AffectDecisioner, TrainDate, TrainCompany, BelowPersonsum, MiddlePersonsum, HighPersonsum, DecisionPersonsun, CustomerMgrName, LectorName, AddUserName, PersonSum, TrainHistory, Painful, Pullulation, TradeName, SaleadviserName, BargainReason, BargainDispute, BargainNum)
{
    this.Code = Code;
    this.OrderId = OrderId;
    this.ThodometerId = ThodometerId;
    this.PrelectDate = PrelectDate;
    this.IsBargain = IsBargain;
    this.IsStandard = IsStandard;
    this.IsValue = IsValue;
    this.JWXID = JWXID;
    this.IsGripe = IsGripe;
    this.GripeExplain = GripeExplain;
    this.IsClass = IsClass;
    this.ClassExplain = ClassExplain;
    this.TeachPlace = TeachPlace;
    this.CustomerPromis = CustomerPromis;
    this.TutorId = TutorId;
    this.DeptId = DeptId;
    this.Explain = Explain;
    this.Adduser = Adduser;
    this.Addtime = Addtime;
    this.EXP1 = EXP1;
    this.EXP2 = EXP2;
    this.EXP3 = EXP3;
    this.EXP4 = EXP4;
    this.DeptName = DeptName;
    this.UName = UName;
    this.HmDate = HmDate;
    this.Expr2 = Expr2;
    this.HmType = HmType;
    this.OrderCode = OrderCode;
    this.CustomerCode = CustomerCode;
    this.State = State;
    this.Province = Province;
    this.City = City;
    this.Area = Area;
    this.Address = Address;
    this.CustomerName = CustomerName;
    this.MnemonicCode = MnemonicCode;
    this.IsHQ = IsHQ;
    this.Decisionmaker = Decisionmaker;
    this.DecisionPosition = DecisionPosition;
    this.DecisionTel = DecisionTel;
    this.DecisionEmail = DecisionEmail;
    this.CompanyCreateDate = CompanyCreateDate;
    this.CompanyProduct = CompanyProduct;
    this.CompanyAttention = CompanyAttention;
    this.CompanyGain = CompanyGain;
    this.ProductSum = ProductSum;
    this.CusTestimony = CusTestimony;
    this.CusTrainbudget = CusTrainbudget;
    this.ManagerQuestion = ManagerQuestion;
    this.StrongPoint = StrongPoint;
    this.Expr1 = Expr1;
    this.Character = Character;
    this.DecisionFancy = DecisionFancy;
    this.DecisionBirthday = DecisionBirthday;
    this.Credit = Credit;
    this.SchoolScientifc = SchoolScientifc;
    this.BirthdayType = BirthdayType;
    this.Homeplace = Homeplace;
    this.CustomerPhylogeny = CustomerPhylogeny;
    this.AffectDecisioner = AffectDecisioner;
    this.TrainDate = TrainDate;
    this.TrainCompany = TrainCompany;
    this.BelowPersonsum = BelowPersonsum;
    this.MiddlePersonsum = MiddlePersonsum;
    this.HighPersonsum = HighPersonsum;
    this.DecisionPersonsun = DecisionPersonsun;
    this.CustomerMgrName = CustomerMgrName;
    this.LectorName = LectorName;
    this.AddUserName = AddUserName;
    this.PersonSum = PersonSum;
    this.TrainHistory = TrainHistory;
    this.Painful = Painful;
    this.Pullulation = Pullulation;
    this.TradeName = TradeName;
    this.SaleadviserName = SaleadviserName;
    this.BargainReason = BargainReason;
    this.BargainDispute = BargainDispute;
    this.BargainNum = BargainNum;
}
